import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@v/Layout'
import { isLogin } from '@/utils/index.js'
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@v/LoginPage')
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('@v/NotFound')
  }
]
/* {
      path: '/userInfo',
      name: '个人中心',
      component: 'UserInfo'
    }, */
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
// 路由鉴权
router.beforeEach((to, from, next) => {
  const passRoutes = ['/login']
  if (passRoutes.includes(to.path)) {
    next()
  } else {
    // 非登录页 鉴权
    if (isLogin()) {
      next()
    } else {
      next('/login')
    }
  }
})
export default router
// import { createRouter, createWebHistory } from 'vue-router'
// import Layout from '@v/Layout'
// import { isLogin } from '@/utils'
// const routes = [
//   {
//     path: '/',
//     name: 'layout',
//     component: Layout
//   },
//   {
//     path: '/login',
//     name: 'login',
//     component: () => import('@v/LoginPage')
//   },
//   {
//     path: '/:pathMatch(.*)*',
//     name: 'NotFound',
//     component: () => import('@v/NotFound')
//   }
// ]

// const router = createRouter({
//   history: createWebHistory(process.env.BASE_URL),
//   routes
// })

// // 路由鉴权
// router.beforeEach((to, from, next) => {
//   const passRoutes = ['/login']
//   if (passRoutes.includes(to.path)) {
//     next()
//   } else {
//     // 非登录页 鉴权
//     if (isLogin()) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })
// export default router
